﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Raven.Client.Indexes;
using LogManager.Base;
using LogManager.Base.Models.Projections;

namespace LogManager.LocalStorage.Indexes
{
    public class Events_TypePerLog : AbstractIndexCreationTask<Event,EventsTypesPerLogProjection>
    {
        public Events_TypePerLog()
        {
            Map = events =>
                from e in events
                select new { LogName = e.LogName, Type = e.Type, Count = 1 };

            Reduce = results =>
                from r in results
                group r by new { LogName = r.LogName, Type = r.Type } into g
                select new { LogName = g.Key.LogName, Type = g.Key.Type, Count = g.Sum(x => x.Count) };                     
        }
    }
}
